<template>
  <el-input
    class="input"
    type="textarea"
    :disabled="isReadonly"
    :rows="config.rows ? config.rows : 5"
    v-model="inputVal"
    @change="change"
    :placeholder="isReadonly ? '' : `请输入${config.name}`"
    clearable
    :maxlength="config.maxlength ? config.maxlength : 200"
    :show-word-limit="true"
  >
  </el-input>
</template>
<script>
export default {
  props: {
    isReadonly: {
      type: Boolean,
      default: false,
    },
    formData: Object,
    config: {
      type: Object,
      default: () => Object.create(null),
    },
  },
  data() {
    return {
      inputVal: null,
    };
  },
  computed: {
    curVal() {
      return this.formData[this.config.prop] || "";
    },
  },
  watch: {
    curVal: {
      immediate: true,
      deep: true,
      handler(val) {
        this.inputVal = val;
      },
    },
  },
  methods: {
    change(val) {
      this.inputVal = val;
      this.formData[this.config.prop] = val;
      this.$emit("update:formData", this.formData);
      this.$emit("change", this.config.prop);
    },
  },
};
</script>
<style lang="scss" scoped></style>
